# 作者：要努力，努力，再努力
# 开发时间：2022/4/28 21:11
import time


def show_info():
    print('0. 退出 1. 查看登录日志')


# 记录日志
def write_logininfo(username):
    with open('log.txt', 'a', encoding='utf-8') as afile:
        s = f'用户名{username}，登录时间：{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))}'
        afile.write(s + '\n')


# 读取日志
def read_logininfo():
    with open('log.txt', 'r', encoding='utf-8') as rfile:
        while True:
            line = rfile.readline()
            if line == '':
                break
            else:
                print(line, end='')


if __name__ == "__main__":
    username = input('用户名：')
    password = input('密码')
    if username == 'admin' and password == 'admin':
        print('登录成功')
        write_logininfo(username)
        show_info()
        while True:
            num = int(input('输入数字：'))
            if num == 0:
                print('退出成功')
                break
            elif num == 1:
                print('查看日志')
                read_logininfo()
                show_info()
                continue
            else:
                print('输入数字有误')
                show_info()
                continue
    else:
        print('用户名密码不正确')
